<?php
/**
 * 获取本周所有日期
 * Array
(
[1] => 2018-06-18
[2] => 2018-06-19
[3] => 2018-06-20
[4] => 2018-06-21
[5] => 2018-06-22
[6] => 2018-06-23
[7] => 2018-06-24
)
 */
function get_week($time = '', $format='Y-m-d'){
//    $time = $time != '' ? $time : time();
    //获取当前周几
    $week = date('w', $time);
    $date = [];
    for ($i=1; $i<=7; $i++){
        $date[$i] = date($format ,strtotime( '+' . ($i-$week) .' days', $time));
    }
    return $date;
}
/**
 * 获取最近七天所有日期
 * Array
(
[1] => 2018-06-13
[2] => 2018-06-14
[3] => 2018-06-15
[4] => 2018-06-16
[5] => 2018-06-17
[6] => 2018-06-18
[7] => 2018-06-19
)
 */
function get_weeks($time = '', $format='Y-m-d'){
//    $time = $time != '' ? $time : time();
    //组合数据
    $date = [];
    for ($i=1; $i<=7; $i++){
        $date[$i] = date($format ,strtotime( '+' . ($i-7) .' days', $time));

    }
    return $date;
}
/*
 * 获取月份
 */
function get_months($time = '',$l=3, $format='Y-m')
{
    $time = $time != '' ? $time : time();

    $date = [];
    for ($i=0; $i<=$l; $i++){
        $date[$i] = date($format ,strtotime( '-' . $i .' months', $time));
    }
    return $date;
}